#!/usr/bin/env python
# coding=utf-8

import unittest
import time
from utility import base
"""
    1,热启动APP进入我tab
    2，查看是否有会员中心入口
    3，如果有点击会员中心  
    4，查看是苹果支付还是微信支付
"""

class AvipCenterTests(base.BaseTests):
    def test_goto_vipCenter(self):
        time.sleep(2)
        #登出
        self.logout()
        #登录
        self.login('18210817745','123456')
        time.sleep(5)
        self.tap_tab_index(2)
        time.sleep(4)
        self.tap_tab_index(4)

        time.sleep(1)
        #查看是否有我的课程，有-点击，没有-报错退出
        vip_center_tab = self.driver.find_element_by_xpath(u'//XCUIElementTypeStaticText[@name="开通享特权"]')
        self.assertIsNotNone(vip_center_tab, u'应该存在一个[开通享特权]按钮')
        vip_center_tab.click()

        time.sleep(1)

        # 断言是否有
        buynow_button = self.driver.find_element_by_xpath(u'//XCUIElementTypeOther[@name="超级会员"]/XCUIElementTypeOther[4]')
        if buynow_button:
            buynow_button.click()
        time.sleep(1)
        # 断言是否进入非核心购买用户
        supervip_button = self.driver.find_element_by_xpath(u'// XCUIElementTypeStaticText[ @ name = "超级会员"])[2]')
        if supervip_button:
            print ('找到超级会员入口，核心用户页面')
            self.driver.save_screenshot("/Users/fisher/workspace/codes/QA/testimg/非核心用户购买页.png")
        else:
            self.driver.save_screenshot("/Users/fisher/workspace/codes/QA/testimg/核心用户购买页.png")





if __name__ == '__main__':
    test_suite = unittest.TestLoader().loadTestsFromTestCase(AvipCenterTests)
    unittest.TextTestRunner().run(test_suite)
